package com.theydream.qeechain.ARcaught;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.theydream.qeechain.R;
import com.theydream.qeechain.battle.Battle;
import com.theydream.qeechain.globaldata.GlobalData;

public class ARDialog extends Activity {
	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.ar_dialog);

		// Draw the caught bear
		Drawable drawable = getResources()
				.getDrawable(
						getResources()
								.getIdentifier(
										GlobalData
												.getInstance()
												.getPetList()
												.get(GlobalData.getInstance()
														.getArID()).getPic(),
										"drawable", "com.theydream.qeechain"));
		Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

		ImageView iv = (ImageView) findViewById(R.id.ARbear_1);
		iv.setImageBitmap(bitmap);

		File sdImageMainDirectory = new File("/sdcard");
		java.io.File file = new java.io.File(sdImageMainDirectory, "/image.jpg");
		if (file.exists()) {

			Bitmap bm = BitmapFactory.decodeFile(sdImageMainDirectory
					.toString() + "/image.jpg");

			Drawable d = new BitmapDrawable(bm);
			RelativeLayout rl = (RelativeLayout) findViewById(R.id.layout);

			rl.setBackgroundDrawable(d);
		}

	}

	public void toBattle(View target) {
		Intent intent = new Intent(this, Battle.class);
		Bundle bundle = new Bundle();
		bundle.putString("eid", GlobalData.getInstance().getArID());
		intent.putExtras(bundle);
		startActivity(intent);
		this.finish();
	}
}